package cn.ncu.wechat.controller;

import cn.ncu.wechat.model.Admin;
import cn.ncu.wechat.service.AdminService;
import cn.ncu.wechat.util.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/api/admin")
public class adminController {
    @Autowired
    private AdminService adminService;
    @GetMapping("/administrators")
    public Result getAdminList(@RequestParam(defaultValue = "1") Integer page,
                               @RequestParam(defaultValue = "10") Integer pageSize,
                               @RequestParam(defaultValue = "-1") String keyword) {
        return adminService.getAdminList(page, pageSize, keyword);
    }

    @PostMapping("/administrators")
    public Result updateOrAddAdmin(@RequestBody Map<String, Object> request) {
        return adminService.updateOrAddAdmin(request);
    }

    @PostMapping("/administrators/{id}/password")
    public Result changePassword(@PathVariable Long id, @RequestBody Map<String, String> request) {
        return adminService.changePassword(id,request);
    }

    @PostMapping("/login")
    public Result<?> login(@RequestBody Admin admin){
        return adminService.login(admin);
    }
}
